$OpenBSD: patch-ansi_c,v 1.4 2015/09/11 14:04:59 jasper Exp $

Security fix for CVE-2015-6806,
screen: Stack overflow due to deep recursion causing process freeze

--- ansi.c.orig	Fri Dec  5 14:57:05 2003
+++ ansi.c	Tue Sep  1 14:03:33 2015
@@ -2425,13 +2425,13 @@ int n, ys, ye, bce;
     return;
   if (n > 0)
     {
+      if (ye - ys + 1 < n)
+	n = ye - ys + 1;
       if (n > 256)
 	{
 	  MScrollV(p, n - 256, ys, ye, bce);
 	  n = 256;
 	}
-      if (ye - ys + 1 < n)
-	n = ye - ys + 1;
 #ifdef COPY_PASTE
       if (compacthist)
 	{
@@ -2482,14 +2482,14 @@ int n, ys, ye, bce;
     }
   else
     {
-      if (n < -256)
-	{
-	  MScrollV(p, n + 256, ys, ye, bce);
-	  n = -256;
-	}
       n = -n;
       if (ye - ys + 1 < n)
 	n = ye - ys + 1;
+      if (n > 256)
+	{
+	  MScrollV(p, - (n - 256), ys, ye, bce);
+	  n = 256;
+	}
 
       ml = p->w_mlines + ye;
       /* Clear lines */
